import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'app_color.dart';

class AppText extends StatelessWidget {
  const AppText(
    this.text, {
    super.key,
    this.style,
    this.fontSize,
    this.color,
    this.fontWeight,
    this.textAlign = TextAlign.left, // 默认左对齐
    this.maxLines,
    this.overflow,
    this.lineHeight,
    this.shadows,
  });

  // 核心参数：文本内容（必传）
  final String text;

  // 样式参数：默认值对应项目统一样式，支持外部覆盖
  final TextStyle? style;

  // 单独暴露字体大小，优先级高于 style
  final double? fontSize;

  // 单独暴露字体颜色，优先级高于 style
  final Color? color;
  final FontWeight? fontWeight;
  final TextAlign? textAlign;
  final int? maxLines;
  final TextOverflow? overflow;

  final double? lineHeight;

  final List<Shadow>? shadows;

  @override
  Widget build(BuildContext context) {
    // 默认样式
    const baseStyle = TextStyle(
      fontSize: 15,
      color: Colors.grey,
      fontWeight: FontWeight.normal,
      // height: 1.4,
    );

    // 2. 合并样式：外部传入的 style > 单独暴露的参数（fontSize/color等）> 基础样式
    final mergedStyle = baseStyle
        .merge(style)
        .copyWith(
          fontSize: (fontSize ?? style?.fontSize ?? baseStyle.fontSize!).sp,
          color: color ?? style?.color ?? baseStyle.color,
          fontWeight: fontWeight ?? style?.fontWeight ?? baseStyle.fontWeight,
          height: lineHeight ?? style?.height,
          shadows: shadows,
        );

    return Text(
      text,
      style: mergedStyle,
      textAlign: textAlign,
      maxLines: maxLines,
      overflow: overflow,
    );
  }

  /// 标题样式：默认16号黑色粗体
  ///
  /// 注意：todo 子标题的其他样式下面扩展
  factory AppText.title(
    String text, {
    TextStyle? style,
    Color? color = Colors.white,
    FontWeight? fontWeight = FontWeight.bold,
    double? fontSize = 15,
    TextAlign? textAlign,
  }) {
    return AppText(
      text,
      style: style,
      color: color,
      fontWeight: fontWeight,
      fontSize: fontSize,
      textAlign: textAlign,
    );
  }

  factory AppText.secondary(
    String text, {
    TextStyle? style,
    Color? color = AppColor.white_60,
    FontWeight? fontWeight,
    double? fontSize = 14,
    TextAlign? textAlign,
  }) {
    return AppText(
      text,
      style: style,
      color: color,
      fontWeight: fontWeight,
      fontSize: fontSize,
      textAlign: textAlign,
    );
  }

  factory AppText.videoShadowTitle(
    String text, {
    TextStyle? style,
    Color? color = Colors.white,
    FontWeight? fontWeight = FontWeight.bold,
    double? fontSize = 16,
    TextAlign? textAlign,
  }) {
    return AppText(
      text,
      style: style,
      color: color,
      fontWeight: fontWeight,
      fontSize: fontSize,
      textAlign: textAlign,
      shadows: const [
        Shadow(
          color: Colors.black, // 阴影颜色（深色阴影对比更明显）
          offset: Offset(0, 1), // 阴影偏移（x: 水平偏移，y: 垂直偏移）
          blurRadius: 2, // 阴影模糊半径（值越大越模糊）
        ),
      ],
    );
  }

  factory AppText.videoShadowSecondary(
    String text, {
    TextStyle? style,
    Color? color = AppColor.white_60,
    FontWeight? fontWeight,
    double? fontSize = 14,
    TextAlign? textAlign,
    int? maxLines,
    TextOverflow? textOverflow
  }) {
    return AppText(
      text,
      style: style,
      color: color,
      fontWeight: fontWeight,
      fontSize: fontSize,
      textAlign: textAlign,
      maxLines: maxLines,
      overflow: textOverflow,
      shadows: const [
        Shadow(
          color: Colors.black, // 阴影颜色（深色阴影对比更明显）
          offset: Offset(0, 1), // 阴影偏移（x: 水平偏移，y: 垂直偏移）
          blurRadius: 2, // 阴影模糊半径（值越大越模糊）
        ),
      ],
    );
  }
}
